package com.hdj.chapter11;

import java.util.ArrayList;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author hedajiang
 * @create 2017/12/14
 * @since 1.0.0
 */
public class TreeNode {

    private Integer id; //id
    private String name; //名称
    private Integer parentId; //父节点
    private Integer level; //层级
    private List<TreeNode> childNodes;

    public TreeNode(String name) {
        this.name = name;
    }

    /**
     * 刪除子节点
     * @param treeNode
     */
    public void removeChildNode(TreeNode treeNode){
        childNodes.remove(treeNode);
    }

    /**
     * 刪除多个子节点
     * @param treeNodes
     */
    public void removeChildNodes(List<TreeNode> treeNodes){
        childNodes.removeAll(treeNodes);
    }

    /**
     * 添加子节点
     * @param treeNode
     */
    public void addChildNode(TreeNode treeNode){
        if(childNodes == null){
            childNodes = new ArrayList<TreeNode>();
        }
        childNodes.add(treeNode);
    }

    /**
     * 添加多个子节点
     * @param treeNodes
     */
    public void addChildNodes(List<TreeNode> treeNodes){
        if(childNodes == null){
            childNodes = new ArrayList<TreeNode>();
        }
        childNodes.addAll(treeNodes);
    }


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public List<TreeNode> getChildNodes() {
        return childNodes;
    }

    public void setChild(List<TreeNode> treeNodes) {
        this.childNodes = treeNodes;
    }

    @Override
    public String toString() {
        return "TreeNode{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", parentId=" + parentId +
                ", level=" + level +
                ", childNodes=" + childNodes +
                '}';
    }
}